package com.baselibrary.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

public class ToastUtils {
    private final static String TAG = "ToastUtils";
    private static Toast mToast = null;
    private static long oneTime;
    private static long twoTime;
    static String oldMsg;

    public static void showShort(Context context, int resId) {
        String msg;
        try {
            msg = context.getResources().getString(resId);
        } catch (Exception e) {
            msg = TAG + ": " + e.getMessage();
        }
        showShort(context, msg);
    }

    public static void showShort(final Context context, final String msg) {
        if (null == context || null == msg || msg.equals("") || msg.length() == 0) {
            return;
        }
        HKToastUtils.showToast(msg);
    }

    public static void showLong(Context context, int resId) {
        String msg;
        try {
            msg = context.getResources().getString(resId);
        } catch (Exception e) {
            msg = TAG + ": " + e.getMessage();
        }
        showShort(context, msg);
    }

    public static void showLong(final Context context, final String msg) {
        if (null == context || null == msg || msg.equals("") || msg.length() == 0) {
            return;
        }
        HKToastUtils.showToast(msg);
    }

    public static void showView(final Context context, final View view) {
        if (null == context || null == view) {
            return;
        }
        view.post(new Runnable() {
            @Override
            public void run() {
                try {
                    Toast mToast = new Toast(context);
                    mToast.setView(view);
                    mToast.setGravity(Gravity.CENTER, 0, 0);
                    mToast.show();
                } catch (Exception e) {

                }
            }
        });
    }
}
